//
//  UIButton+HLExtension.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/17.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "UIButton+HLExtension.h"

@implementation UIButton (HLExtension)

- (instancetype)initWithTitle:(NSString *)title withTitleFont:(CGFloat)titleFont withBackImageName:(NSString *)backImageName
{
    self = [super init];
    if (self) {
        //设置文字
        [self setTitle:title forState:UIControlStateNormal];
        //设置文字大小
        self.titleLabel.font = [UIFont systemFontOfSize:titleFont];
        //设置背景图片
        [self setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",backImageName]] forState:UIControlStateHighlighted];
        //设置自适应大小
        [self sizeToFit];
    }
    return self;
}

- (instancetype)initWithImageName:(NSString *)imageName withBackImageName:(NSString *)backImageName
{
    self = [super init];
    if (self) {
        //设置图片
        if (imageName != nil) {
            [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
            [self setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState:UIControlStateHighlighted];
        }
        if (backImageName != nil) {
            [self setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal];
            [self setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",backImageName]] forState:UIControlStateHighlighted];
        }
        //设置自适应大小
        [self sizeToFit];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title withTitleFont:(CGFloat)titleFont withImageName:(NSString *)imageName withBackImageName:(NSString *)backImageName withTitleColor:(UIColor *)titleColor {
    self = [super init];
    if (self) {
        //设置文字
        [self setTitle:title forState:UIControlStateNormal];
        //设置文字大小
        self.titleLabel.font = [UIFont systemFontOfSize:titleFont];
        //设置背景图片
        [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        
        [self setTitleColor:titleColor forState:UIControlStateNormal];
//        [self setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState:UIControlStateHighlighted];
        [self setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",backImageName]] forState:UIControlStateSelected];
        
        //设置自适应大小
        [self sizeToFit];
    }
    return self;
}

@end
